#include<bits/stdc++.h>
using namespace std;
int n,a[20],b[20],c[20],ans=0;
void dfs(int u,int pre0,int pre1,int sum){
    if(u==n+1){
        //for(int i=1;i<=n;i++)cout<<b[i]<<" ";
        //cout<<sum<<endl;
        ans=max(ans,sum);
        return;
    }
    int nsum1=sum,nsum2=sum;
    if(a[pre0]==a[u])nsum1+=a[u];
    dfs(u+1,u,pre1,nsum1);
    b[u]=1;
    if(a[pre1]==a[u])nsum2+=a[u];
    dfs(u+1,pre0,u,nsum2);
    b[u]=0;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=1;i<=n;i++)scanf("%d",&a[i]);
        dfs(1,0,0,0);
        printf("%d\n",ans);
    }
    return 0;
}//20
